Allow grid to use style variation blockGap values for columns calcula…#10906
Allow grid to use style variation blockGap values for columns calcula…#10906tellthemachines wants to merge 6 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * @param array $registered_styles Currently registered block styles. | ||
| * | ||
| * @return string|null The name of the first registered variation, or null if none found. |
There was a problem hiding this comment.
| * @param array $registered_styles Currently registered block styles. | |
| * | |
| * @return string|null The name of the first registered variation, or null if none found. | |
| * @param array $registered_styles Currently registered block styles. | |
| * @return string|null The name of the first registered variation, or null if none found. |
Per document standard https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/#1-functions-class-methods
| ) | ||
| ); | ||
|
|
||
| // WP_Theme_JSON_Resolver::clean_cached_data(); |
There was a problem hiding this comment.
Do we actually need this code here, or was it added by mistake?
There was a problem hiding this comment.
It was added in tear_down method so better to remove it from test.
There was a problem hiding this comment.
Ah, well spotted! I was experimenting and forgot to remove it 😅
| 'type' => 'grid', | ||
| 'columnCount' => 3, | ||
| 'minimumColumnWidth' => '12rem', | ||
|
|
| // Clean up. | ||
| remove_theme_support( 'appearance-tools' ); |
There was a problem hiding this comment.
This should go in tear_down, yeah?
There was a problem hiding this comment.
I'm not sure. I'm seeing adding/removing of theme supports per test in most places, and the support is added inside the test so I thought I'd remove it there too. Though for this one I guess it won't make any difference practically, because it's removed at the end of the test.
There was a problem hiding this comment.
Actually thinking better about it, we shouldn't need appearance-tools support here at all!
| * @param string $class_name CSS class string for a block. | ||
| * @param array $registered_styles Currently registered block styles. |
There was a problem hiding this comment.
Can the array param be more specific? For example (if this is accurate):
| * @param string $class_name CSS class string for a block. | |
| * @param array $registered_styles Currently registered block styles. | |
| * @param string $class_name CSS class string for a block. | |
| * @param array<string, array<string, mixed>> $registered_styles Currently registered block styles. |
| $prefix = 'is-style-'; | ||
| $len = strlen( $prefix ); | ||
|
|
||
| foreach ( explode( ' ', $class_name ) as $class ) { | ||
| if ( str_starts_with( $class, $prefix ) ) { | ||
| $variation = substr( $class, $len ); |
There was a problem hiding this comment.
Best to not abbreviate the variable names:
| $prefix = 'is-style-'; | |
| $len = strlen( $prefix ); | |
| foreach ( explode( ' ', $class_name ) as $class ) { | |
| if ( str_starts_with( $class, $prefix ) ) { | |
| $variation = substr( $class, $len ); | |
| $prefix = 'is-style-'; | |
| $length = strlen( $prefix ); | |
| foreach ( explode( ' ', $class_name ) as $class ) { | |
| if ( str_starts_with( $class, $prefix ) ) { | |
| $variation = substr( $class, $length ); |
| * | ||
| * @return string|null The name of the first registered variation, or null if none found. | ||
| */ | ||
| function wp_get_variation_name_from_class( $class_name, $registered_styles = array() ) { |
There was a problem hiding this comment.
| function wp_get_variation_name_from_class( $class_name, $registered_styles = array() ) { | |
| function wp_get_variation_name_from_class( string $class_name, $registered_styles = array() ): ?string { |
There was a problem hiding this comment.
Just a couple of thoughts re: the new utility function (sorry I didn't catch this in the Gutenberg PR!):
- Would
wp_get_variation_name_from_classbe better placed inblock-style-variations.php? - There's an existing function
wp_get_block_style_variation_name_from_classthat accepts only a single param (class name). Would it be worth it to combine the logic into that existing function, with the optional second param? I.e. if the second param is empty, simply check against the classname, but if it's given a list of registered variations, then iterate over the list to find from the actual list of variations? - Alternately, still have this be a separate function, but give it consistent naming with the existing utility function, and co-locate it beside that function
Hope that all made sense, it's a useful function, though, and sounds like a good addition overall to me 👍
6d3822f to
54f1554
Compare
Yeah that's a good question. Also, it looks like Otherwise, I think we could consolidate the two functions into one. |
Oh, good point. Yeah, just as in Still, I don't mind the additional check (and the idea of adding it into the existing function via a second param) as it does give an additional polish of making sure that we're only looking up values that can exist. Up to you, I think, if you prefer the clarity or "correctness" of the additional check, or the simplicity of re-using the existing function. (Personally I think it's a valid choice either way). |
|
Hmm I might try reusing the existing function for consistency. |
d568f4f to
f24eb61
Compare
Actually, looking closer at I'll add a test for the new function too. |
Ah, fair enough! To make sure the name is distinct from the existing function would it be worth renaming the new function to something like:
Up to you, but I'd lean toward co-locating it with the other function, just because they're both global functions, and it sometimes feels a little odd when similar utility functions are in different locations. Though I get that it also makes sense to keep it close to where it's mostly used! If so, you could always put |
Yeah that sounds good, I'll rename it!
It could be used somewhere else, so it's probably best for the name not to imply otherwise. I like to have single use utilities live where they're used for code reading convenience, though that's a personal preference. But I don't think we have any clear cut rules around this sort of thing. If it ever gets used elsewhere in block supports, I'd be inclined to move it to |
|
All sounds reasonable to me! |
Co-authored-by: Weston Ruter <westonruter@gmail.com>
andrewserong
left a comment
There was a problem hiding this comment.
This is testing well for me on the server-side / site-frontend with the custom block style from WordPress/gutenberg#75360, and it sounds like the in-editor behaviour will land when gutenberg is resynced with trunk later in the week.
Looks like @westonruter's feedback's been addressed, so this all LGTM! Thanks for all the back and forth 👍
|
Thanks for the reviews folks! |
…tion
Trac ticket: https://core.trac.wordpress.org/ticket/64624
Syncs changes from WordPress/gutenberg#75360.
Use of AI Tools
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.